package com.aaa.service.impl;

import com.aaa.dao.ViewTestResultFpaDao;
import com.aaa.entity.ResultDiv;
import com.aaa.entity.ViewTestResultFpa;
import com.aaa.service.ViewTestResultFpaService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * (ViewTestResultFpa)表服务实现类
 *
 * @author
 * @since 2022-07-08 10:00:04
 */
@Service("viewTestResultFpaService")
public class ViewTestResultFpaServiceImpl implements ViewTestResultFpaService {
    @Resource
    private ViewTestResultFpaDao viewTestResultFpaDao;

    /**
     * 分页查询
     *
     * @param viewTestResultFpa 筛选条件
     * @param pageRequest       分页对象
     * @return 查询结果
     */
    @Override
    public Page<ViewTestResultFpa> queryByPage(ViewTestResultFpa viewTestResultFpa, PageRequest pageRequest) {
        long total = this.viewTestResultFpaDao.count(viewTestResultFpa);
        return new PageImpl<>(this.viewTestResultFpaDao.queryAllByLimit(viewTestResultFpa, pageRequest), pageRequest, total);
    }

    /**
     * @param viewTestResultFpa
     * @return Map
     * @create by: feng (zhaixing@163.com)
     * @description: 根据id查询对应信息
     * @create time: 2022/7/15 15:46
     */
    @Override
    public Map<String, Double> queryRequestById(ViewTestResultFpa viewTestResultFpa) {
        ViewTestResultFpa Result = this.viewTestResultFpaDao.queryResultFpaById(viewTestResultFpa);
        Map<String, Double> map = new HashMap<>();
        map.put("redCount", Result.getRedCount());
        map.put("yellowCount", Result.getYellowCount());
        map.put("blueCount", Result.getBlueCount());
        map.put("greenCount", Result.getGreenCount());
        return map;
    }

    /**
     * @param
     * @return Map<String, Integer>
     * @create by: feng (zhaixing@163.com)
     * @description: 查询所有数据
     * @create time: 2022/7/15 16:14
     */
    @Override
    public Map<String, Integer> queryAllPlanFpa() {
        List<ViewTestResultFpa> viewTestResultFpas = this.viewTestResultFpaDao.queryAllPlanFpa();
        int r = 0, y = 0, b = 0, g = 0, f = 0;
        for (ViewTestResultFpa viewTestResultFpa : viewTestResultFpas) {
            double red = viewTestResultFpa.getRedCount();
            double yellow = viewTestResultFpa.getYellowCount();
            double blue = viewTestResultFpa.getBlueCount();
            double green = viewTestResultFpa.getGreenCount();
            if (red > yellow && red > blue && red > green) {
                r++;
            } else if (yellow > red && yellow > blue && yellow > green) {
                y++;
            } else if (blue > red && blue > yellow && blue > green) {
                b++;
            } else if (green > red && green > yellow && green > blue) {
                g++;
            } else {
                f++;
            }
        }
        Map<String, Integer> map = new HashMap<>();
        map.put("r", r);
        map.put("y", y);
        map.put("b", b);
        map.put("g", g);
        map.put("f", f);
        return map;
    }

    /**
     * @param
     * @return java.util.List<com.aaa.entity.ViewTestResultFpa>
     * @create by: feng (zhaixing@163.com)
     * @description: 查询所有，排重
     * @create time: 2022/7/20 14:17
     */
    @Override
    public List<ViewTestResultFpa> queryAllResultFpa() {
        List<ViewTestResultFpa> viewTestResultFpas = this.viewTestResultFpaDao.queryAllResultPlanFpa();
        return viewTestResultFpas;
    }
    /**
     * @Author zhouhangyong
     * @Description //TODO
     * @Date 18:28 2022/7/20
     * @Param
     * @return
     **/
    @Override
    public List<ResultDiv> queryAllResultDiv(Integer id) {
        return  viewTestResultFpaDao.queryAllDiv(id);
    }
    /**
     * @create by: feng (zhaixing@163.com)
     * @description: 删除
     * @create time: 2022/7/22 20:09
     * @param testId
     * @return
     */
    @Override
    public boolean deleteResultById(String testId) {
        Integer integer = this.viewTestResultFpaDao.delResultFpa(testId);
        if (integer>0){
            return true;
        }
        return false;
    }
}
